/**
 * 
 */
package com.eagle.coders.core.dynamic.compiler;

import java.io.IOException;

import javax.tools.FileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
import javax.tools.StandardJavaFileManager;

/**
 * @author Anees
 * 
 */
public class DynamicClassFileManager<FileManager> extends
		ForwardingJavaFileManager<JavaFileManager> {

	private ByteArrayClassLoader loader = null;

	DynamicClassFileManager(StandardJavaFileManager mgr) {
		super(mgr);
		try {
			/* 2 */loader = new ByteArrayClassLoader();
		} catch (Exception ex) {
			ex.printStackTrace(System.out);
		}
	}

	@Override
	/* 3 */public JavaFileObject getJavaFileForOutput(Location location,
			String name, Kind kind, FileObject sibling) throws IOException {
		ByteArrayJavaFileObject co = new ByteArrayJavaFileObject(name, kind);
		loader.put(name, co);
		return co;
	}

	@Override
	/* 4 */public ClassLoader getClassLoader(Location location) {
		return loader;
	}
}
